<template>
    <div class="jifen-content">
        <div v-if="this.signatureData" class="jifentop" :style="jfbg">
            <div v-if="this.today === this.signatureData.signedDate" class="jifen1">
                <i class="iconfont icon-jifenqiandao"></i>
                <span>已签到</span>
            </div>
            <div v-else class="jifen1">
                <span @click="makeSign">点我签到</span>
            </div>
            <p class="jifen2">已连续签到{{ signatureData.totalDay }}天，继续加油！</p>
            <div class="jifen3">
                您当前积分
                <p>{{ signatureData.integral }}</p>
            </div>
        </div>
        <div class="jifencenter">
            <!-- <Calendar ref="Calendar" :sundayStart="true" v-on:isToday="clickToday" v-on:choseDay="clickDay" v-on:changeMonth="changeDate"></Calendar> -->
            <Calendar ref="Calendar" :sundayStart="true"></Calendar>

        </div>
    </div>
</template>

<script>
import Calendar from '../../components/Calendar.vue'
import {mapState,mapActions} from 'vuex'
export default {
    // created() {
    //     function format(date, index) {
    //         date = new Date(date)
    //         return `${date.getFullYear()}-${date.getMonth() + 1}-${index}`
    //     }
    // }
    created(){
        this.checkSignature();
    },
    components: {
        Calendar
    },
    data() {
        return {
            jfbg:{
                backgroundImage: "url(" + require("../../assets/images/jfbg.png") + ")",
                backgroundRepeat: "no-repeat",
                backgroundSize: "100% 100%",
                backgroundPosition: '50% 50%'
            }
        }
    },
    computed:{
        ...mapState({
            signatureData: state => state.personModules.signatureData,
        }),
        today(){
            let date = new Date();
            let seperator1 = "-";
            let year = date.getFullYear();
            let month = date.getMonth() + 1;
            let strDate = date.getDate();
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
            let currentdate = year + seperator1 + month + seperator1 + strDate;
            return currentdate;
        }
    },
    methods: { 
        ...mapActions({
            checkSignature:'personModules/checkSignature',
            makeSignature:'personModules/makeSignature'
        }),
        makeSign(){
            this.makeSignature();
        }
        // clickDay(data) {
        //     console.log(data)
        //     this.$toast(data)
        // },
        // clickToday(data) {
        // },
        // changeDate(data) {
        // }
    }
}
</script>

<style lang="scss" scoped>
@import "../../assets/style/order.scss";
</style>



